function displayViewedItemsAjax()
{
	$("#recentlyViewed").html('');
	
	$.ajax({
		type:'post',
		url:displayViewedItemsAjaxUrl,
		dataType:"json",
		cache: false,
		async: true,
		success: function(value) 
		{  
			if(value != null && value.length > 0)
			{
				var htmlContent = displayViewedItems(value);
    			$("#recentlyViewed").append(htmlContent);
    			$("#browse").show();
    			$("#recentlyViewed").find('img').lazyLoad({
    				effect:'fadeIn',
    				effectDuration:200,
    				onload : function(){
    					this[0].style.background = 'none';
    				}
    			});
			}
			else
			{
				$("#browse").css('display','none');
			}
		}
	});
}

function displayViewedItems(jsonData)
{
	if(jsonData==undefined || jsonData.length==0)
	{
		return '';
	}
	var dataListContent = '';
	for(var i = 0; i < jsonData.length; i++)
	{
		dataListContent += displayOneViewedItems(jsonData[i]);
	}

	return dataListContent
}

function displayOneViewedItems(oneJsonData)
{
	var htmlContent = "";
//	htmlContent = '<li><a href="##productUrl##" target="_blank" class="pic"><img alt="##productName##" src="##loading##" longdesc="##productImage##" width="60" height="60"/></a><a href="##productUrl##" title="##productName##" target="_blank" class="tit">##productName##</a><div class="price" title="单价"><em>&yen;##productPrice##</em></div></li>';
//	htmlContent = htmlContent.replace(/##id##/g,oneJsonData.id);
//	htmlContent = htmlContent.replace(/##productName##/g,oneJsonData.productName);
//	htmlContent = htmlContent.replace(/##productUrl##/g,oneJsonData.productUrl);
//	htmlContent = htmlContent.replace(/##loading##/g,placeUrl);
//	htmlContent = htmlContent.replace(/##loadingSmall##/g,loadingSmallUrl);
//	htmlContent = htmlContent.replace(/##productImage##/g,oneJsonData.productImage);
//	htmlContent = htmlContent.replace(/##productUrl##/g,oneJsonData.productUrl);
//	htmlContent = htmlContent.replace(/##productPrice##/g,oneJsonData.productPrice);
	htmlContent = '<li><a href="##productUrl##" target="_blank" class="pic"><img alt="##productName##" src="##loading##" longdesc="##productImage##" width="60" height="60"/></a><a href="##productUrl##" title="##productName##" target="_blank" class="tit">##productName##</a><div class="price" title="单价"><em>&yen;##productPrice##</em></div></li>';
	htmlContent = htmlContent.replace(/##id##/g,oneJsonData.id);
	htmlContent = htmlContent.replace(/##productName##/g,oneJsonData.productName);
	htmlContent = htmlContent.replace(/##productNameShort##/g,oneJsonData.productNameShort);
	htmlContent = htmlContent.replace(/##productUrl##/g,oneJsonData.productUrl);
	htmlContent = htmlContent.replace(/##loading##/g,placeUrl);
	htmlContent = htmlContent.replace(/##productImage##/g,oneJsonData.productImage);
	htmlContent = htmlContent.replace(/##productUrl##/g,oneJsonData.productUrl);
	htmlContent = htmlContent.replace(/##productPrice##/g,oneJsonData.productPrice);

	return htmlContent;
}

function addItem2ComparedAjaxM()
{
	var productIds = ""
	$('input[@type=checkbox][name=selectComparedViewed][checked]').each(function(i){
			if(i!=0)
			{
				productIds +=",";
			}
			productIds +=$(this).val();
		});
	addItem2ComparedAjax(productIds);
}

function deleteViewedItemsAjax()
{
	wep.dialog({
		title : '消息提示',
		content : '你确定清空所有浏览记录？',
		onyes : function(){
			$.ajax({
				type:'post',
				url: deleteViewedItemsAjaxUrl,
				dataType:"json",
				cache: false,
				async: true,
				success: function(value) 
				{  
					 $("#browse").hide();
				}
			});
		},
		onno : function(){
			this.hide();
		},
		width : 300,
		lock : true,
		icoBasePath : imagesUrl,
		icon : 'info.gif'
	});
}

function addOneQty()
{
	var pro_count = $("#pro_count").val();
	if(isNaN(parseInt(pro_count)) || parseInt(pro_count)==0)
	{
		pro_count = 1;
	}
	if(pro_count < 99)
	{
		pro_count++;
		$("#pro_count").val(pro_count);
	}
}
function subOneQty()
{
	var pro_count = $("#pro_count").val();
	if(isNaN(parseInt(pro_count)) || parseInt(pro_count)==0)
	{
		pro_count = 1;
	}

	pro_count--;

	if(pro_count==0)
	{
		pro_count=1;
	}
	lastNum = pro_count;
	$("#pro_count").val(pro_count);
}

function changePage(pageV,category)
{
	page = pageV;
	if(category == '1')
	{
		displayCommentAjaxData();
		location.hash = '#promember_reprot';
	}
	if(category == '2')
	{
		displayScoreCommentAjaxData();
		//location.hash = '#proclient_report';
		typeof window.cmtPageChange === 'function' && cmtPageChange.call(null, pageV);
	}
	if(category == '3')
	{
		displayTryReport();
	}
}

//获取平均分
function getAvgScore()
{
	jQuery.ajax({
		type:'post',
		url: getAvgScoreUrl,
		data:{'id':productId},
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			if(value != null && value.success == 1)
			{
				var data = value.info;
				var integer = "0";
				var decimal = ".0";
				var score = data.score;
				var countN = data.countN;
				if(score != null)
				{
					if(score < 10)
					{
						integer = score.substring(0,1);
						decimal = score.substring(1,3);
					}
					else
					{
						integer = score.substring(0,2);
						decimal = '';
					}
				}
				else
				{
					score = 0;
				}
				if(countN == null)
				{
					countN = 0;
				}
				
				var html = '';
				if(countN)
				{
					html += '<span>('+countN+')个评分</span>';
				}
				html += '<em style="width:'+score*10+'%"></em>';
				$('#comment_pro_star').attr('title',score+'分，'+countN+'个评分').html(html);
				$("#score_value").html('<strong class="val">'+integer+'<sub>'+decimal+'</sub></strong><strong class="val mask">'+integer+'<sub>'+decimal+'</sub></strong>');
				$("#star_count").html('<strong class="star"><em style="width:'+Math.round(score)*10+'%">'+score+'</em></strong><span class="count">共<em>'+countN+'</em>人评分</span>');
			}
		}
	});
}

function getValidateCode(obj)
{
	var validateCodeUrl = getValidateCodeUrl+'?t='+Math.random();
	obj.value="";
	$(obj).next().html('<img id="validate_code_img_id" src="' + validateCodeUrl + '" height="30" width="100" alt="验证码" />');
	return;
}


//会员评论
function displayCommentAjaxData()
{
	var ajaxData = {'productId':productId,'page':page};
	jQuery.ajax({
		type:'post',
		url: getCommentDataJsonUrl,
		data:ajaxData,
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			displayComment(value);
		}
	});
}

function displayComment(value)
{
	jQuery("#comment_html").html('');
	if(value != null && value.consultList != null)
	{
		var data = value.consultList;
		var totalPage = value.page.pageCount;
		var startPage = value.page.pageStart;
		var endPage = value.page.pageEnd;
		var dataCount = value.page.count;
		$("#question").html('即时提问（'+dataCount+'）');
		var pagerContent = buildSpecialPager(page,totalPage,startPage,endPage,1);
		$("#pager2").html('');
		$("#pager2").html(pagerContent);
		var htmlContent = "";
		for(var i = 0; i < data.length; i++)
		{
			htmlContent +=	'<div class="cmt_item consult_item';
			if(i % 2 != 0)
			{
				htmlContent +=	' even';
			}
			htmlContent += ' ">';
			htmlContent +=	'	<div class="cmt_header">';
			htmlContent +=	'		<a href="javascript:;" target="_blank" class="pic">' +
				'<span class="curr"><img src="/resources/images/pcweb/noavatar_middle.gif" ' +
				'height="56" width="56" alt="'+data[i].memberName+'" /></span><i></i></a>';
			htmlContent +=	'		<strong class="name">'+data[i].memberName+'</strong>';
			htmlContent +=	'		<i class="arrow"><b></b></i>';
			htmlContent +=	'	</div>';
			htmlContent +=	'	<div class="cmt_main">';
			htmlContent +=	'		<p data-commentid = "'+data[i].consultId+'">'+data[i].consultContent+'</p>';
			htmlContent +=	'		<span class="timer">'+data[i].addTimeStr+'</span>';
			htmlContent +=	'	</div>';
			htmlContent +=	'	<div class="consult_reply">';
			if(data[i].consultReply != null )
			{
				//var manager = data[i].manager_replys;
				//for(var j=0; j < manager.length; j++)
				//{
					htmlContent +=	'		<div class="cmt_header">';
					htmlContent +=	'			<a href="javascript:;" class="pic">' +
						'<span class="curr"><img src="/resources/images/pcweb/noavatar_middle.gif" height="56" width="56" alt="'+data[i].storeName+'" /></span><i></i></a>';
					htmlContent +=	'			<strong class="name">'+data[i].storeName+'</strong>';
					htmlContent +=	'			<i class="arrow"><b></b></i>';
					htmlContent +=	'		</div>';
					//break;
				//}
				htmlContent +=	'		<div class="cmt_main">';
				//for(var j=0; j < manager.length; j++)
				//{
					htmlContent +=	'			<p>'
					htmlContent +=					data[i].consultReply;
					//if(isLogin && isCustomerService)
					//{
					//	htmlContent +=					'</br>';
					//	htmlContent +=					'<a style="color:#c00;" class="del" href="javascript:;" onclick="deleteComment();return false;">[ 删除 ]</a>'
					//}
					htmlContent +=  '			</p>';
					htmlContent +=	'			<span class="timer">'+data[i].replyTimeStr+'</span>';
				//}
				htmlContent +=	'		</div>';
			}
			htmlContent +=	'	</div>';
			//if(isLogin && isCustomerService)
			//{
			//	htmlContent +=	'	<div class="cmt_adm">';
			//	htmlContent +=	'		<a href="javascript:void(0)" onclick="deleteComment('+data[i].id+',1);return false;" class="del" title="删除"><span>删除</span></a>';
			//	htmlContent +=	'		<a href="#" class="rep consult_rep" title="回复"><span>回复</span></a>';
			//	htmlContent +=	'	</div>';
			//}
			htmlContent +=	'</div>';
		}
		$("#comment_html").html(htmlContent);
	}
}

//客户评论
function displayScoreCommentAjaxData()
{
	//$('#pro_cmt_all').html('<p class="loading"><img src="'+loadingUrl+'" alt="Loading..." /></p>')
	var ajaxData = {'page':page,'productId':productId};
	jQuery.ajax({
		type:'post',
		url : getScoreCommentJsonUrl,
		data:ajaxData,
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			displayScoreComment(value);
		}
	});
}

function displayScoreComment(value)
{
	var htmlContent = '';
	var data = value.evaluateGoodsList;
	
	var shaidanDataCount =  0;
	if(shaidanDataCount == undefined)
	{
		shaidanDataCount = 0;
	}	
	//$("#shaidan-count").html('（'+shaidanDataCount+'）');
	
	if(data != null && data.length > 0)
	{
		var totalPage = value.page.pageCount;
		var startPage = value.page.pageStart;
		var endPage = value.page.pageEnd;
		var dataCount = value.page.count;
		
		if($("#new_tab a").hasClass("current"))
		{
			$("#new-comment-count").html('（'+dataCount+'）');
			$("#comment_count").html('客户评价（'+dataCount+'）');
		}
		
		
		var pagerContent = buildSpecialPager(page,totalPage,startPage,endPage,2);
		htmlContent += '<div class="cmt_top"></div>';
		for(var i = 0; i < data.length; i++)
		{
			//if(data[i].parent_id == 0)
			//{
				htmlContent += '<div class="cmt_item">';
				htmlContent += '	<div class="cmt_item_inner">';
				htmlContent += '		<div class="cmt_header">';
				htmlContent += '			<a href="javascript:;" target="_blank" class="pic"><span class="curr"><img src="/resources/images/pcweb/noavatar_middle.gif" height="56" width="56" alt="'+data[i].gevalFrommembername+'" /></span><i></i></a>';
				htmlContent += '			<strong class="name">'+data[i].gevalFrommembername;
				//if(data[i].imageList.length > 0){
				//	htmlContent += '			<span>晒单</span>';
				//}
				htmlContent += '</strong>';
				
				htmlContent += '			<span class="timer">'+data[i].gevalAddtimeStr+'</span>';
				//if(data[i].is_addcomment == "n")
				//{
				//	if(data[i].score == null)
				//	{
				//		data[i].score = 0;
				//	}
					htmlContent += '			<strong class="star" title="'+data[i].gevalScores+'分"><em style="width:'+data[i].gevalScores*10*2+'%">'+data[i].gevalScores+'</em></strong>';
				//}
				htmlContent += '			<i class="arrow"><b></b></i>';
				htmlContent += '		</div>';
				htmlContent += '		<div class="cmt_main"><div class="evaluate">';
				//if(data[i].is_addcomment == "y"){
				//	htmlContent += '		<span class="title">追加评价：</span>';
				//}else{
					htmlContent += '		<span class="title">评价：</span>';
				//}
				htmlContent += '			<p>';
				htmlContent += data[i].gevalContent+'</p></div>';

				if(data[i].imageList.length > 0)
				{
					var imgs = data[i].imageList;
					//晒单图片
					htmlContent += '		<div class="shareorder_list">';
					htmlContent += '		用户晒单：';
					for(var k = 0; k < imgs.length; k++){
						htmlContent += '<a href="#" target="_blank"><img src="" width="52" height="52" /></a>';
					}
					htmlContent += '		<span>共'+data[i].imageList.length+'张图片</span>';
					htmlContent += '		<a href="#" class=" btn_copera btn see_shareorder" target="_blank"><span>查看晒单</span></a>';
					htmlContent += '		</div>';
				}
				
				//var q = 1;
				//for(var j = 0; j < data.length; j++)
				//{
				//	if(data[j].parent_id == data[i].id && data[j].second_parent_id == 0)
				//	{
				//		htmlContent += '		<div class="cmt_reply">';
				//		htmlContent += '			<i>'+q+'</i>';
				//		if(data[j].is_manager == 1)
				//		{
				//			htmlContent += '			<span class="pic"><img src="http://passport.feng.com/ucenter/avatar.php?uid='+data[j].user_id+'&size=small" height="37" width="37" alt="威锋商城客服" /></span>';
				//			htmlContent += '			<span class="name">威锋商城客服:</span>';
				//		}
				//		else
				//		{
				//			htmlContent += '			<span class="pic"><img src="http://passport.feng.com/ucenter/avatar.php?uid='+data[j].user_id+'&size=small" height="37" width="37" alt="'+data[j].user_name+'" /></span>';
				//			htmlContent += '			<span class="name">'+data[j].user_name+':</span>';
				//		}
				//		htmlContent += '			<span class="timer">'+data[j].create_time+'</span>';
				//		htmlContent += '			<div class="main" data-commentid="'+data[i].id+'" data-parentId="'+data[j].id+'">';
				//		htmlContent += '				<p>'+data[j].comment+'<p>';
				//		htmlContent += '			</div>';
				//		htmlContent += '			<div class="cmt_adm">';
				//		if(isLogin && isCustomerService)
				//		{
				//			htmlContent += '			<a href="javascript:;" class="rep" title="客服回复"><span>回复</span></a>';
				//			htmlContent += '			<a href="javascript:;" onclick="deleteComment('+data[j].id+',2);return false;" class="del" title="删除"><span>删除</span></a>';
				//		}
				//		htmlContent += '			</div>';
				//		htmlContent += '		</div>';
				//		q++;
				//		if(data[j].manager_replys != null && data[j].manager_replys.length > 0)
				//		{
				//			var replys = data[j].manager_replys;
				//			for(var k = 0; k < replys.length; k++)
				//			{
				//				htmlContent += '		<div class="cmt_reply">';
				//				htmlContent += '			<i>'+q+'</i>';
				//				htmlContent += '			<span class="pic"><img src="http://passport.feng.com/ucenter/avatar.php?uid='+replys[k].user_id+'&size=small" height="37" width="37" alt="威锋商城客服" /></span>';
				//				htmlContent += '			<span class="name">威锋商城客服:</span>';
				//				htmlContent += '			<span class="timer">'+replys[k].create_time+'</span>';
				//				htmlContent += '			<div class="main">';
				//				htmlContent += '  				<blockquote><span class="name">@'+data[j].user_name+'</span>'+data[j].comment+'</blockquote>';
				//				htmlContent += '				<p>'+replys[k].comment+'<p>';
				//				htmlContent += '			</div>';
				//				htmlContent += '		</div>';
				//				q++;
				//			}
				//		}
				//	}
				//}
				htmlContent += '		</div>';
				htmlContent += '		<div class="cmt_btns">';
				//htmlContent += '			<a id="useful_'+data[i].id+'" href="javascript:;" class="agree" onclick="commentUseful('+data[i].id+',1);return false;" useful ="'+data[i].useful+'"><span>有用(<em>'+data[i].useful+'</em>)</span></a>';
				//htmlContent += '			<a id="nouse_'+data[i].id+'" href="javascript:;" class="oppose" onclick="commentUseful('+data[i].id+',0);return false;" nouse = "'+data[i].nouse+'"><span>反对(<em>'+data[i].reply_num+'</em>)</span></a>';
				//htmlContent += '			<a id="bindReply_'+data[i].id+'" href="javascript:;" class="cmmt" onclick="bindReply('+data[i].id+');return false;" ><span>回复(<em>'+data[i].reply_num+'</em>)</span></a>';
				htmlContent += '		</div>';
				//if(isLogin && isCustomerService)
				//{
				//	htmlContent += '		<div class="cmt_adm">';
				//	htmlContent += '			<a href="javascript:;" onclick="deleteComment('+data[i].id+',2);return false;" class="del" title="删除"><span>删除</span></a>';
				//	htmlContent += '		</div>';
				//}
				//htmlContent += '		<div id="replyCustomerComment_'+data[i].id+'" class="cmt_inpts" style="display: none;">';
				//htmlContent += '			<form action="">';
				//htmlContent += '			<div class="txt_panel">';
				//htmlContent += '				<div class="txt"><input type="hidden" id="reply_hidden_'+data[i].id+'" name="reply_hidden_'+data[i].id+'" value="0"><label for="reply_score_content_'+data[i].id+'">在此回复...</label><textarea id="reply_score_content_'+data[i].id+'"></textarea></div>';
				//htmlContent += '			</div>';
				//htmlContent += '			<div class="ext_panel">';
				//htmlContent += '				<a href="javascript:;" onclick="replyCustomerComment(this,'+data[i].id+');" class="btn send"><span>发表</span></a>';
				//htmlContent += '				<a href="javascript:;" onclick="cancelReply('+data[i].id+')" class="btn cancel"><span>取消</span></a>';
				//htmlContent += '				<span class="chk_code">';
				//htmlContent += '					<label for="reply_score_code_'+data[i].id+'">验证码：</label>';
				//htmlContent += '					<input type="text" id="reply_score_code_'+data[i].id+'" value="点击获取" onfocus="getValidateCode(this)" style="color: rgb(204, 204, 204)"/><span></span>';
				//htmlContent += '				</span>';
				//htmlContent += '			</div>';
				//htmlContent += '		</form>';
				//htmlContent += '	</div>';
				htmlContent += '</div>';
				htmlContent += '</div>';
			//}
		}
		htmlContent += '<div class="cmt_bottom"></div>';
		htmlContent += '<div class="cmt_pager">';
		htmlContent += 	pagerContent;
		htmlContent += '</div>';
		htmlContent += '</div>';
		htmlContent += '</div>';
	}
	$("#pro_cmt_all").html(htmlContent);
	$("#pro_cmt_all2").html(htmlContent);
}

function customer_reply(id,pid,name)
{
	$("#replyCustomerComment_"+pid).removeClass('cmt_inputs_min');
	$("#reply_hidden_"+pid).val(id);
	$("#reply_score_content_"+pid).val("@"+name+" ").focus();
}

//save会员评论
function saveComment()
{
	var content = $("#comment_content").val();
	if(content)
	{
		content = content.replace(/^\s*/, '');
	}
	if(content == null || content == "")
	{
		showInfoTip('内容不能为空！','info');
		return;
	}
	var commentCode = $("#commentCode").val();
	if(commentCode == null || commentCode == "")
	{
		showInfoTip('请输入验证码！','info');
		return;
	}
	var productId = $("#productId").val();
	jQuery.ajax({
		type:'post',
		url: saveCommentUrl,
		data:{'content':content,'commentCode':commentCode,'id':productId},
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			if(value.success == "1")
			{
				$("#comment_content").val('');
				$("#commentCode").val('点击获取');
				$("#comment_div").addClass('cmt_inputs_min');
				page = 1;
				displayCommentAjaxData(productId);
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});
}

function cancelReply(id)
{
	$("#reply_score_content_"+id).val('');
	//$("#replyCustomerComment_"+id).addClass('cmt_inputs_min');
	$("#replyCustomerComment_"+id).hide();
}

function cancelComment()
{
	$("#comment_content").val('');
	$("#comment_div").addClass('cmt_inputs_min');
}

//save客户评论
function saveCustomerComment()
{
	var content = $("#newscore_comment").val();
	if(content)
	{
		content.replace(/^\s*/, '');
	}
	if(content == null || content == "")
	{
		showInfoTip('评论不能为空！','info');
		return;
	}
	var code = $("#comm12_code").val();
	if(code=="" || code=="点击获取")
	{
		showInfoTip('请输入验证码！','info');
		return;
	}
	var anonymity = 0;
	if($("#anon").attr("checked")==true)
	{
		anonymity = 1;
	}
	jQuery.ajax({
		type:'post',
		url : saveCustomerCommentUrl,
		data:{'content':content,'code':code,'anonymity':anonymity,'id':productId},
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{  
			if(value.success == "1")
			{
				var _mvq = window._mvq || [];window._mvq = _mvq;
				_mvq.push(['$setAccount', 'm-28955-0']);
				_mvq.push(['$setGeneral', 'consult', '',  md5UserName, userId]);
				_mvq.push(['$logConversion']);
				page = 1;
				displayScoreCommentAjaxData();
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});
}

function deleteComment(id,category)
{
	if(!confirm('确定删除吗？')){
		return;
	}
	var ajaxData = {'id':id,'category':category};
	jQuery.ajax({
		type:'post',
		url: deleteCommentUrl,
		data:ajaxData,
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{  
			if(value.success == 1)
			{
				if(category == 1)
				{
					displayCommentAjaxData();
				}
				if(category == 2 || category == 3)
				{
					displayScoreCommentAjaxData();
				}
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});	
}

//回复客户评论
function replyCustomerComment(obj,id)
{
	var content = $("#reply_score_content_"+id).val();
	var replyCode = $("#reply_score_code_"+id).val();
	if(content)
	{
		content = content.replace(/^\s*/, '')
	}
	if(content=="")
	{
		showInfoTip('回复内容不能为空！','info');
		return;
	}
	if(replyCode=="" || replyCode=="点击获取")
	{
		showInfoTip('请输入验证码！','info');
		return;
	}
	cancelReply(id);
	jQuery.ajax({
		type:'post',
		url: replyScoreCommentAjaxUrl,
		data:{"productId":productId,"code":replyCode,"content":content,"parentId":id,"isCustomerService":isCustomerService},
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			if(value.success==1)
			{
				displayScoreCommentAjaxData();
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});
}


//有用没用
function commentUseful(id,category)
{
	$("#useful_"+id).replaceWith('<a id="useful_'+id+'" href="javascript:;" class="agree disabled"><span>有用(<em>'+$("#useful_"+id).children().children().html()+'</em>)</span></a>');
	//$("#nouse_"+id).replaceWith('<a id="nouse_'+id+'" href="javascript:;" class="oppose disabled"><span>反对(<em>'+$("#nouse_"+id).children().children().html()+'</em>)</span></a>');
	jQuery.ajax({
		type:'post',
		url: commentUsefulUrl,
		data:{"id":id,"category":category},
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			if(value.success == 1)
			{
				if(category == '1')
				{
					$("#useful_"+id).replaceWith('<a id="useful_'+id+'" href="javascript:;" class="agree disabled"><span>有用(<em>'+value.info+'</em>)</span></a>');
					//$("#nouse_"+id).replaceWith('<a id="nouse_'+id+'" href="javascript:;" class="oppose disabled"><span>反对(<em>'+$("#nouse_"+id).children().children().html()+'</em>)</span></a>');
				}
				if(category == '0')
				{
					$("#useful_"+id).replaceWith('<a id="useful_'+id+'" href="javascript:;" class="agree disabled"><span>有用(<em>'+$("#useful_"+id).children().children().html()+'</em>)</span></a>');
					//$("#nouse_"+id).replaceWith('<a id="nouse_'+id+'" href="javascript:;" class="oppose disabled"><span>反对(<em>'+value.info+'</em>)</span></a>');
				}
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});	
}

//支持评论
function supportComment(commentId,score)
{
	var ajaxData = {"commentId":commentId,"score":score};
	jQuery.ajax({
		type:'post',
		url: supportUrl,
		data:ajaxData,
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			if(value.success==1)
			{
				if(score == 'score')
				{
					$("#score_comment_agree_"+commentId).replaceWith('<a id="score_comment_agree_'+commentId+'" href="javascript:;" class="report_agree" style="cursor:default">支持('+value.info+')</a>');
					$("#score_comment_oppose_"+commentId).replaceWith('<a id="score_comment_oppose_'+commentId+'" href="javascript:;" class="report_oppose" style="cursor:default">'+jQuery("#score_comment_oppose_"+commentId).html()+'</a>');
				}
				else
				{
					$("#comment_agree_"+commentId).replaceWith('<span class="report_agree">支持('+value.info+')</span>');
					$("#comment_oppose_"+commentId).replaceWith('<span class="report_oppose">'+jQuery("#comment_oppose_"+commentId).html()+'</span>');
				}
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});
}

//反对评论
function opposeComment(commentId,score)
{
	var ajaxData = {"commentId":commentId,"score":score};
	jQuery.ajax({
		type:'post',
		url: opposeUrl,
		data:ajaxData,
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			if(value.success==1)
			{
				if(score == 'score')
				{
					$("#score_comment_agree_"+commentId).replaceWith('<a id="score_comment_agree_'+commentId+'" href="javascript:;" class="report_agree" style="cursor:default">'+jQuery("#score_comment_agree_"+commentId).html()+'</a>');
					$("#score_comment_oppose_"+commentId).replaceWith('<a id="score_comment_oppose_'+commentId+'" href="javascript:;" class="report_oppose" style="cursor:default">反对('+value.info+')</a>');
				}
				else
				{
					$("#comment_agree_"+commentId).replaceWith('<span class="report_agree">'+jQuery("#comment_agree_"+commentId).html()+'</span>');
					$("#comment_oppose_"+commentId).replaceWith('<span class="report_oppose">反对('+value.info+')</span>');
				}
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});
}

function addFavorite(productId,obj)
{
	var ajaxData = {"product_id":productId};
	jQuery.ajax({
		type:'post',
		url: addFavoriteUrl,
		data:ajaxData,
		dataType:"json",
		cache: false,
		async: true,
		success: function(value)
		{
			var icon = "";
			if(value.success=="1")
			{
				$(obj).replaceWith('<span class="pro_atten">已收藏</span>');
				showInfoTip(value.info+'，点击<a href="'+addFavoriteIndexUrl+'" target="_blank" style="color:#09f; font-weight:bold; text-decoration:underline">查看我的收藏</a>','success');
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});
}

function checkQty(obj)
{
	var qty = $(obj).val();
	if(!/[^0-9-]+/.test(qty))
	{
		qty = parseInt(qty);
		if(qty < 1)
		{
			$(obj).val(lastNum);
		}else
		{
			lastNum = qty;
		}
	}
	else
	{
		$(obj).val(lastNum);
	}
}

function refreshDisplayCrosssellItems(){
	$.ajax({
		type:'post',
		url: getCrossellItemsUrl,
		dataType:"json",
		data:{"productId":productId},
		cache: false,
		async: true,
		success: function(value){
			if(value.success=="1"){
				displayCrosssellItemsDataListContent(value.info.crosssellItems);
			}else{
				wep.dialog({
					   title : '消息',
					   content : value.info,
					   onyes : function(){
							this.close();
					   },
					   width : 200,
					   lock : true
				});
			}
		}
	});
}

function displayCrosssellItemsDataListContent(jsonData){
	var dataListContent = '';
	for(var i = 0; i < jsonData.length; i++){
		dataListContent += displayCrosssellOneRecord(jsonData[i],i);
	}
	if(dataListContent == '')
	{
		$("#guess_love").hide();
	}
	else
	{
		$("#guess_love").show();
		$("#guess_love_items").append(dataListContent).find('img').lazyLoad({
			effect:'fadeIn',
			effectDuration:200,
			onload : function(){
				this[0].style.background = 'none';
			}
		});
	}
}

function displayCrosssellOneRecord(oneJsonData,i){
	var htmlContent = '';
	
	htmlContent += '<li class="clearfix">';
	htmlContent += '<a href="'+oneJsonData.url+'" target="_blank">';
	htmlContent += '<img src="'+placeUrl+'" longdesc="'+oneJsonData.imgsrc+'" width="80" height="80" style="background:url('+loadingSmallUrl+') no-repeat 50% 50%" />';
	htmlContent += '</a>';
	htmlContent += '<a href="'+oneJsonData.url+'" target="_blank" class="name" title="'+oneJsonData.title+'">'+oneJsonData.title+'</a>';
	htmlContent += '<em>&yen;'+oneJsonData.price+'</em>';
	htmlContent += '</li>';
	
	return htmlContent;
}

function bindReply(id)
{
	$("#replyCustomerComment_" + id).toggle(),$("#reply_score_content_" + id).focus();
}

function displayTryReport(){
	$('#pro_cmt_all').html('<p class="loading"><img src="'+loadingUrl+'" alt="Loading..." /></p>')
    $.ajax({
		url : tryReportListUrl,
		data : {
    		"page"  : page ,
			"tryId" :tryId
		},
		type : 'post',
		timeout : 10000,
		timeoutFunction : function() {
			alert("读取超时，请重试！");
		},
		dataType:"json",
		cache: false,
		async: true,
		beforeSend:function(){
		},
		complete:function(){
    		
		},
		success: function(value){
			if(value.success=="1")
			{
				$("#tryreport-count").html('（'+value.page.dataCount+'）');
				var tmpl = $('#tryReport_tmpl').val();
	     	   	var html = ds.tmpl(tmpl, value);
	     	    var pagerContent = buildSpecialPager(page,value.page.totalPage,value.page.startPage,value.page.endPage,3);
	     	    html += '<div class="cmt_pager">'+pagerContent+'</div>';
	     	    $('#pro_cmt_all').html(html);
	     	    
			}
			else
			{
				showInfoTip(value.info,'info');
			}
		}
	});
}

function buildSpecialPager(page,totalPage,startPage,endPage,category){
	if(/[^0-9-]+/.test(page))
	{
		page = 1;
	}
	if(page == 0)
	{
		page = 1;
	}
	if(page > endPage)
	{
		page = endPage;
	}
	var pagerContent = '<div class="list">';
	if(page==1){
		pagerContent += '<a href="javascript:void(0)" title="上一页" class="prev disabled"><span>«</span></a>';
	}else{
		pagerContent += '<a href="javascript:void(0)" title="上一页" onclick="return changePage('+(page-1)+','+category+',this)" class="prev"><span>«</span></a>';
	}
	if(totalPage != 5){
		if(page>=4){
			if(page!=4){
				pagerContent += '<a href="javascript:void(0)" title="第1页"  onclick="return changePage(1,'+category+',this)"><span>1</span></a>';
			}
			if(page>=5){
				pagerContent += '<span class="more"><span>...</span></span>';
			}
		}
	}

	for(i = startPage; i<=endPage; i++){
		pagerContent += '<a href="javascript:void(0)" title="第'+i+'页" onclick="return changePage('+i+','+category+',this)" ';
		if (page == i){
			pagerContent += ' class="current" ';
		}
		pagerContent += '><span>'+i+'</span></a>';
	}

	if(totalPage != 5){
		if(page<=totalPage-3){
			if(page<=totalPage-4){
				pagerContent += '<span class="more"><span>...</span></span>';
			}

			if (endPage != totalPage){
				pagerContent += '<a href="javascript:void(0)" title="第'+totalPage+'页" onclick="return changePage('+totalPage+','+category+',this)"><span>' + totalPage + '</span></a>';
			}
		}
	}

	if(page==totalPage || totalPage == 0){
		pagerContent += '<a href="javascript:void(0)" title="下一页" class="next disabled"><span>»</span></a>';
	}else{
		pagerContent += '<a href="javascript:void(0)" title="下一页" class="next" onclick="return changePage('+(page+1)+','+category+',this)"><span>»</span></a>';
	}
	pagerContent += '</div>';

	return pagerContent;
}